Python Json Cheat Sheet

Table of Contents

Overview

docs of python

The standard library documentation for this module.

http://docs.python.org/2/library/json.html

JavaScript Object Notation

JSON home, with documentation and implementations in other languages.

http://json.org/

simplejso

simplejson, from Bob Ippolito, et al, is the externally maintained development version of the json library included with Python 2.6 and Python 3.0.

https://code.google.com/p/simplejson/

jsonpickle

jsonpickle allows for any Python object to be serialized into JSON.

https://code.google.com/p/jsonpickle/

More Examples

Load and Decoded

import json

data = [ { 'a':'A', 'b':(2, 4), 'c':3.0 } ]
data_string = json.dumps(data)
print 'ENCODED:', data_string

decoded = json.loads(data_string)
print 'DECODED:', decoded

print 'ORIGINAL:', type(data[0]['b'])
print 'DECODED :', type(decoded[0]['b'])
$ python json_simple_types_decode.py

ENCODED: [{"a": "A", "c": 3.0, "b": [2, 4]}]
DECODED: [{u'a': u'A', u'c': 3.0, u'b': [2, 4]}]
ORIGINAL: <type 'tuple'>
DECODED : <type 'list'>

Author: Shi Shougang

Created: 2015-03-05 Thu 23:19

Emacs 24.3.1 (Org mode 8.2.10)

Validate